package com.dp.appi.dao.impl;

import com.dp.appi.dao.ProblemDao;
import com.dp.appi.dao.SysConfigDao;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by chenghao on 2015/9/30.
 */
@Component
public class ProblemDaoImpl extends BaseDaoImpl implements ProblemDao {
    @Override
    public List<Map<String, Object>> getProblemTerm(String orgid) {

        StringBuilder sb = new StringBuilder();
        sb.append( "select * from p_problemterm ppt  where  ppt.editionGuid LIKE (select ppe.guid from p_problemedition ppe where ppe.orgsid like ?  );");

        return   getJdbcTemplate().queryForList(sb.toString(), new Object[]{"%"+orgid+"%"});

   }
    @Override
    public List<Map<String, Object>> getProblem(String orgid) {

        StringBuilder sb = new StringBuilder();
        sb.append( "  select pp.*, ppr.termGuid from  p_problem pp LEFT JOIN  p_problemrelation ppr on pp.guid=ppr.problemGuid ");
        sb.append( "   where ppr.termGuid in (select ppt.guid from p_problemterm ppt  where  ppt.editionGuid LIKE (select ppe.guid from p_problemedition ppe where ppe.orgsid like ?  )); ");
        return   getJdbcTemplate().queryForList(sb.toString(), new Object[]{"%"+orgid+"%"});

    }

    @Override
    public List<Map<String, Object>> getProblemPhoto(String orgid) {

        StringBuilder sb = new StringBuilder();
        sb.append( "  select ppp.* from  p_problemPhoto ppp where   ppp.problemGuid in (select pp.guid from  p_problem pp LEFT JOIN  p_problemrelation ppr on pp.guid=ppr.problemGuid where ppr.termGuid in (select ppt.guid from p_problemterm ppt  where  ppt.editionGuid LIKE (select ppe.guid from p_problemedition ppe where ppe.orgsid like ? )))  ; ");
        return   getJdbcTemplate().queryForList(sb.toString(), new Object[]{"%"+orgid+"%"});

    }

    @Override
    public List<Map<String, Object>> getproblemExist(String stateid) {
        StringBuilder sb = new StringBuilder();
        sb.append( "  select id,guid,bigType,smallType,existDescribe,advice," +
                "problemGuid,finder,UNIX_TIMESTAMP(findTime) as findTime," +
                "note,handler, UNIX_TIMESTAMP(handleTime) as handleTime, " +
                "results,accepter,UNIX_TIMESTAMP(acceptTime) as acceptTime," +
                "pointId,projectId,states " +
                "  from  p_problemexist pp where pp.projectId like ? ;");

        return   getJdbcTemplate().queryForList(sb.toString(), new Object[]{"%"+stateid+"%"});

    }
    @Override
    public List<Map<String, Object>> getproblemExistPhoto(String stateid) {
        StringBuilder sb = new StringBuilder();
        sb.append( "  SELECT  *   from  p_problemExistPhoto ppp  where   ppp.problemExistGuid in(select pp.guid from  p_problemexist pp where pp.projectId like ?) ");
        return   getJdbcTemplate().queryForList(sb.toString(), new Object[]{"%"+stateid+"%"});

    }


}
